﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;

using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using Microsoft.Surface.Presentation.Input;

namespace eGrid_App
{
    /// <summary>
    /// Interaction logic for MapLayersMangerPanel.xaml
    /// </summary>
    public partial class MapLayersMangerPanel : ScatterViewItem
    {

        public MapLayersMangerPanel()
        {
            InitializeComponent();
            LayerCollection layers = MapLayersManager.Instance.MapLayers;
            //Binding layersBinding = new Binding("MapLayersBinding");
            //layersBinding.Source = layers;
            MapLayersListBox.ItemsSource = layers;
        }

        #region Button Event Handlers

        private void Close_Button_Click(object sender, RoutedEventArgs e)
        {
            Visibility = Visibility.Hidden;
        }

        private void AddLayerButton_Click(object sender, RoutedEventArgs e)
        {
            Layer newLayer = MapLayersManager.Instance.AddLayer(IDTextBox.Text, UrlTextBox.Text);
        }

        private void DeleteLayerButton_Click(object sender, RoutedEventArgs e)
        {
            var clickedButton = sender as SurfaceButton;
            var butp = clickedButton.TemplatedParent as ContentPresenter;
            var butpp = butp.Content as Layer;

            if (MapLayersManager.Instance.RemoveLayer(butpp.ID))
            {
                for (int i = 0; i < MapLayersListBox.Items.Count; i++ )
                {
                    var curItem = MapLayersListBox.Items[i] as Layer;
                }
            }
        }

        #endregion
    }
}
